
#include <BStream>
#include <BStyle>
#include "member_BGroupBox.h"
#include "member_BWidget.h"

using namespace BWE;

member_BGroupBox::member_BGroupBox(BGroupBox* groupBox)
{
	boss = groupBox;
	flat = false;
	wired = true;
	checkable = false;
	checked = false;
	foldable = false;
	folded = false;
	ia_align = Align_LeftCenter;
	ia_spacing = 2;
	wireSize = 1;
	dirty = false;
	state = State_Normal;
}
member_BGroupBox::~member_BGroupBox()
{

}

void member_BGroupBox::freshRects(const BStyle* style)
{
	if (style)
		style->translate(boss->title(), t_title);
	else
		t_title.clear();

	BSize textSize;
	if (const BFont* font = style->font())
	{
		if (t_title.size())
			textSize = font->textSize(t_title);
		else
			textSize = font->textSize(boss->title());
	}

	BRect topRect = boss->rect(Part_Top);

	BIcon* icon = boss->titleIcon();
	if (icon || ia_form > Form_TextOnly || checkable)
	{
		BSize realIconSize = iconSize;
		if (realIconSize.width() < 1)
			realIconSize.width() = textSize.height();
		if (realIconSize.height() < 1)
			realIconSize.height() = textSize.height();
		ia_imageSize = realIconSize;
	}
	ia_textSize = textSize;
	titleArea = adjust(topRect);

	int border = boss->border();
	BSize size = boss->size();
	BPerch perch = boss->perch();

	BRectf wireRect;
	wireRect.left() = border + perch.left() / 2.0f;
	wireRect.top() = border + perch.top() / 2.0f;
	wireRect.right() = size.width() - border - perch.right() / 2.0f;
	wireRect.bottom() = size.height() - border - perch.bottom() / 2.0f;
	if (widget_member(boss)->round)
	{
		wirePoints.reset();
		wirePoints.append(BPointf((float)titleArea.right(), wireRect.top()));
		widget_member(boss)->round->createRightTopPoints(wireRect, wirePoints);
		widget_member(boss)->round->createRightBottomPoints(wireRect, wirePoints);
		widget_member(boss)->round->createLeftBottomPoints(wireRect, wirePoints);
		widget_member(boss)->round->createLeftTopPoints(wireRect, wirePoints);
		wirePoints.append(BPointf((float)titleArea.left(), wireRect.top()));
	}
	else
	{
		wirePoints.reset();
		wirePoints.append(BPointf((float)titleArea.left(), wireRect.top()));
		wirePoints.append(wireRect.leftTop());
		wirePoints.append(wireRect.leftBottom());
		wirePoints.append(wireRect.rightBottom());
		wirePoints.append(wireRect.rightTop());
		wirePoints.append(BPointf((float)titleArea.right(), wireRect.top()));
	}
}
